<?php
// This class will generate module skeleton
class HModuleRobot {		
	function generate($module_name) {
		// Insert Module into Database using HModuleAdmin
		HModuleAdmin::insert($module_name);		
		
		$module_path = MODULE_PATH.SEPARATOR.$module_name;
		
		// Create Module Folder
		mkdir($module_path);
		
		// Create index.php
		$fp = fopen($module_path.SEPARATOR.'index.php','w+');
		self::writeCodeBehind($fp, $module_name);
		
		// Create index.html.php
		$fp = fopen($module_path.SEPARATOR.'index.html.php','w+');
	}
	
	function writeCodeBehind($fp, $module_name) {
		define('TAB', '  ');
		fprintf($fp,"<?php \n");
		fprintf($fp,"class ".$module_name." extends HModule { \n");	
		fprintf($fp,TAB."function run() { \n");	
		fprintf($fp,TAB.TAB."echo 'Module ".$module_name." has been created successfully!'; \n");
		fprintf($fp,TAB."} \n");
		fprintf($fp,"} \n");
	}
}